from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
from app.core.setting import setting
from app.middleware.logging_middleware import logging_middleware
from app.core.config.__logging__ import setup_logging
from app.core import lifespan
from app.api.api import api_router

app = FastAPI(
    lifespan=lifespan,
    title="Opentrons Flex Control",
    openapi_url=None if setting.env != "dev" else f"{setting.api_v1}/openapi.json",
    description="""
    Base on Opentrons-Robot-Server, Controlling the Flex on production line.
    Support: andy.hu@opentrons.com
    """,
    version=setting.version
)

# Define middleware
app.add_middleware(
    CORSMiddleware,
    allow_origins=("*"),
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)
app.middleware("http")(logging_middleware)
app.include_router(api_router)
# 启动日志文件
setup_logging()

if __name__ == '__main__':
    uvicorn.run(app)
